import 'package:flutter/material.dart';

import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';

import 'gmapHelper.dart';

class MyMap2 extends StatelessWidget {
  @override
  MyMap2({
    LatLng? location,
    double? zoom,
    List<LayerOptions>? layers,
  }) {
    this.Layers = layers ?? <LayerOptions>[];
    this.Location = location ?? new LatLng(31.95, 103.31);
    this.Zoom = zoom ?? 8.0;
    this.allLayers = _loadLayer();
  }

  late List<LayerOptions> Layers;
  late LatLng Location;
  late double Zoom;
  bool IfDT = false;

  late List<LayerOptions> allLayers;

  List<LayerOptions> _loadLayer() {
    var _layers = GMapHelper.NewLayerList();
    if (IfDT == null) IfDT = true;

    _layers.add(GMapHelper.TileGooleMap());

    //_layers.addAll(GMapHelper.DituLayerList());
    for (var item in Layers) {
      _layers.add(item);
    }
    return _layers;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: new Center(
        child: new FlutterMap(
          options: new MapOptions(
            center: Location,
            zoom: Zoom,
          ),
          layers: allLayers,
        ),
      ),
    );
  }
}
